package dao;

import java.util.LinkedList;
import java.util.List;

import relations.Associate;
import relations.belongsTo;
import relations.handle;
import relations.PaidWith;
import entities.Media_Company;
import entities.Product;
import entities.Album;
import entities.Order;
import entities.User;

public class PaidWithDAO {

	private static final PaidWithDAO instance = new PaidWithDAO();
	private List<PaidWith> pwList;
	//private List<Media_Company>AssociateMediaComp;
	
	private PaidWithDAO(){
		pwList = new LinkedList<PaidWith>();
	
		PaidWith cus = null;
		
		//cus = Associate.newInstance("jaime", "Jaime", "Vazquez", "ja@j.com", 1L, "test", "kl", "1", "00778", "PR", "Gurabo", "USA");
		//belongsTos.add(cus);
		//cus = belongsTo.newInstance("jaime1", "Jaime", "Vazquez", "ja@j.com", 2L, "test", "kl", "1", "00778", "PR", "Gurabo", "USA");
		//belongsTos.add(cus);
	}
	
	public static PaidWithDAO getInstance() {
		return instance;
	}

	public synchronized PaidWith findPaidWith(String creditCardNum, String orderID) {
		PaidWith result = null;
	
		for (PaidWith s : pwList){
			if (s.getCreditCardNum().equals(creditCardNum) && s.getOrderID().equals(orderID)){
				result = s;
			
			}
		}
		
	
		return result;
	}

	public synchronized void addPaidWith(PaidWith obj) throws RecordDuplicateException{
		if (findPaidWith(obj.getCreditCardNum(), obj.getOrderID()) != null){
			throw new RecordDuplicateException("Relation PaidWith with credit card: " + obj.getCreditCardNum() + " and" + " Order ID: " + obj.getOrderID() + " is already in the db.");
		}
		else {
			pwList.add(obj);
			
		}
	}

}
